<?php

	// TITLE: Organization_type AUTO MODEL
	// FILE: scaffolding/model/organization_type.php
	// AUTHOR: AUTOGEN
	// CREATED: 2015/04/20 07:49:57
	// DESCRIPTION: 
	// REQUIREMENTS: 

	$createOrganizationType = function($con, $organizationType) {
		$sql = 'INSERT INTO organization_type (id, title, code, description) VALUES (';
		$sql .= $organization_type->getId() . ', ';
		$sql .= $organization_type->getTitle() . ', ';
		$sql .= $organization_type->getCode() . ', ';
		$sql .= $organization_type->getDescription() . ')';
		$sql .= ')';
		$result = mysqli_query($con, $sql);
		$id = ($result) ? mysqli_insert_id($con) : $result;
		mysqli_close($con);
		return $id;
	};

	$readOrganizationType = function($con, $id) {
		$sql = 'SELECT * FROM organization_type WHERE id = ' . $id;
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$result = mysqli_fetch_array($results);
			$organizationType = new OrganizationType();
			$organizationType->setId(result[0]);
			$organizationType->setTitle(result[1]);
			$organizationType->setCode(result[2]);
			$organizationType->setDescription(result[3]);
		} else {
			$organizationType = false;
		}
		return $organizationType;
	};

	$updateOrganizationType = function($con, $organizationType) {
		$sql = 'UPDATE organization_type SET ';
		$sql .= 'id = ' . $organization_type->getId() . ', ';
		$sql .= 'title = ' . $organization_type->getTitle() . ', ';
		$sql .= 'code = ' . $organization_type->getCode() . ', ';
		$sql .= 'description = ' . $organization_type->getDescription() ;
		$sql .= 'WHERE id = ' . id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$deleteOrganizationType = function($con, $id) {
		$sql = 'DELETE FROM organization_type WHERE id = ' . $id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$listOrganizationType = function($con) {
		$sql = 'SELECT * FROM organization_type';
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$organizationTypes = array();
			while ($result = mysqli_fetch_array($results)) {
				$organizationType = new OrganizationType();
				$organizationType->setId(result[0]);
				$organizationType->setTitle(result[1]);
				$organizationType->setCode(result[2]);
				$organizationType->setDescription(result[3]);
				$organizationTypes[] = organizationType;
			}// end while
		} else {
			$organizationTypes = false;
		}
		return $organizationTypes;
	};

